﻿using System.Collections.Generic;

using PMngr.Data;

namespace PMngr.Main
{
    public partial class WholeApprovalForm : BaseApproval
    {
        private IRepository repository;

        public WholeApprovalForm(IRepository repository, IEnumerable<int> wholeIds)
        {
            this.repository = repository;

            Approved = approvalDt =>
            {
                if (wholeIds != null)
                {
                    foreach (var wId in wholeIds)
                    {
                        var userId = wId;
                        var whole = repository.Find<WholeTransfer>(userId);
                        whole.Approved = true;
                        whole.ApprovalDate = approvalDt;

                        foreach (var profile in whole.Profiles)
                        {
                            profile.ApprovalDate = approvalDt;
                        }
                    }

                    repository.CommitChanges();

                    return true;
                }

                return false;
            };
        }
     
    }
}
